//<script language="Javascript">
<?



///////////////// MULTIPLE USED QUERIES
$_query_dummies [ "mod_news" ][ "list" ]	= "ID, date_format(date, '%d.%m %y') as pdate, <%lang:mod_news.nameid%> as short";
$_query_dummies [ "mod_letter" ][ "list" ]	= "ID, date_format(pdate, '%d.%m %y') as pdate, <%lang:mod_letter.nameid%> as short";

$Modcon = new MOD_CONSTRUCT();


//////////////////  ASSETS  //////////////////
if($_set->wtype == "win") {
//////////////////////////////////////////////

////////////////  TEXT ASSETS (basic)
if($_tool[1] == "basic") {

////////////////// EDIT TEXTMOD
	if($_set->action == "edit.mod" || $_set->action == "edit.new"){
		if($_set->action == "edit.new") {
		
			$_mods = json_decode( $DB->get_key( "page", "ID={$_set->vars->parentid}", "mods" ));
		
			$am = -1; $type = "text";
			if($column = $_mods->{ $_set->vars->ctype }) foreach($column as $key => $mod) {
				$broken = explode(".", $key);
				if(count($broken) > 1 && $broken[0] == $type) $am = (int) array_pop($broken);
				$wtype = $mod->wtype;
			}
		
			$textid = $Engine->text->maxid() + 1;
			$DB->query( "INSERT INTO `txtdump` (`textid`,`lang`,`short`,`llog`,`author`) VALUES ( $textid, '".LANG."', '...', NOW(), ".$_SESSION['uid'].")", 0 );
			$DB->query("INSERT INTO `txtdump` (`textid`,`lang`,`long`,`llog`,`author`) VALUES (" . ++$textid . ", '".LANG."', '...', NOW(), ".$_SESSION['uid'].")", 0 );
			$_mods->{ $_set->vars->ctype }->{"$type.".++$am} = array("wtype"=>($wtype)?$wtype:(($_set->vars->ctype=="main")?"win":"wgt"), "tool"=>"basic", "nameid"=>$textid-1, "textid"=>$textid);
			$DB->query("UPDATE `pages` SET mods='".json_encode($_mods)."', llog=NOW() WHERE `ID`=".$_set->vars->parentid, 0 );
			$json = json_encode($_mods->{ $_set->vars->ctype }->{"$type.".$am});
			?>
			$(ref.vars.id+".box").appendChild( win.float.el({id:"<?=$_set->vars->parentid.".".$_set->vars->ctype.".$type.$am"?>", type:'mod', action:'edit.mod', tool:'basic', name:"...", descr:"text block", meta: {"page": "<?=$_set->vars->parentid?>", column: "<?=$_set->vars->ctype?>", mod: "<?="$type.$am"?>", modvars: <?=$json?>}}) );
			win.asset.dropbox.list[ref.vars.id].floats.push("<?=$_set->vars->parentid.".".$_set->vars->ctype.".$type.$am"?>");
			win.asset.dropbox.sortable("<?=$_set->vars->type;?>");
			<?
			
		}
		
		if( !$_mod = $_set->vars->meta->modvars) $_mod = json_decode($json);

		if( $shortraw = $Engine->text->filter( $_mod->nameid ))
			foreach( $shortraw as $l ) $short[$l['lang']] = $l['short']; else $short = array();
		
		if( $longraw = $Engine->text->filter( $_mod->textid, "long" ))
			foreach($longraw as $l) $long[$l['lang']] = stripslashes($l['long']);  else $long = array();
	?>	
		ref.seed([
			tag("font", {style:"font-size:18px"}, "<?=$_set->vars->descr;?> "), tag("font", {id:ref.id+".title"}, "\"<?=$short[LANG]?>\""), br,
			tag("input", {id:ref.id+".title.input"}),
			tag("div", {id:ref.id+".text"}),
			tag("div", {id:ref.id+".comment",class:"comment"})
		]);
		
		[{id:ref.id+".title.input",descr:'titel', direct:1, traceback:[<?= ($_set->vars->traceback)? json_encode($_set->vars->traceback).", ":""; ?>ref.id+".title"], textid:<?=($_mod->nameid)? $_mod->nameid:0?>, values:<?=json_encode($short)?>},
		{id:ref.id+".text", rich:1, descr:'content', direct:1, textid:<?=($_mod->textid)? $_mod->textid:0?>, values:<?=json_encode($long)?>}].each(function(obj){ win.asset.txtfield.build(obj); });
		
	<? exit(); }
}

////////////////  NEWSLETTER ASSETS
if($_tool[1] == "letter") {

////////////////// LIST NEWSLETTERS
	if($_set->action == "list"){ ?>

		ref.seed([
			tag("font", {style:"font-size:18px"}, "<?= ucfirst($_set->vars->descr)?>"), br, br,
			new List({id:ref.id+".lst", tool:'text.letter', descr:'<?=$_set->vars->boxdescr?>', new:'add <?=$DB->type_r( $_set->vars->objtype )?>', meta:ref.vars})
		]);
	
		$(ref.id+".lst").seed(<?= $_set->parse_list() ?>);


////////////////// EDIT NEWSLETTER
	<? } else if($_set->action == "edit" || $_set->action == "edit.new"){ 
		if( $_set->action == "edit.new" ) {
			
			$DB->query("INSERT INTO mod_letter (type, pdate, flog, creator, meta) VALUES (".$_set->vars->objtype.", NOW(), NOW(), ".$Engine->user("ID").", '{\"year\":2010, \"theme\":\"" . engine_get('theme') . "\"}')", 0 );
			$_set->vars->id = $DB->get_key( "text.letter", "active=0 order by ID desc", "ID" );
			?>
			
			if(ref.vars.parent) {
				win.float.list["float_"+ref.vars.type+".<?=$_set->vars->id?>"] = obj = {id:<?=$_set->vars->id?>, type:ref.vars.type, tool:'text.letter', name:"...", descr:"...", objtype:ref.vars.objtype, list:[{ref:'id'}, {ref:'descr'}, '<?=date("d.m y")?>'], meta:{} };
				$(ref.vars.parent).vars.floatlist.push(<?=$_set->vars->id?>);
				$(ref.vars.parent+".tbody").insert({top: new win.trfloat(obj)});
			}
			<?
		}
		
		$letterloc	= $Modcon->request_json( engine_get('style:mod.letter.vars') );
		$letterloc	= $DB->get_key( "page", "ID=".$letterloc->location , "name" );
		
		$_letter	= $DB->get( "text.letter", "ID=". $_set->vars->id, "*, YEAR(pdate) as year, MONTH(pdate) as month, DAY(pdate) as day, HOUR(pdate) as hour" );
		$title		= $Engine->text->filter( $_letter['nameid'] );
		$body		= $Engine->text->filter( $_letter['textid'], "long" );
		$meta		= $_letter['meta'];
		$theme		= json_decode($meta)->theme;
	
		?>
		
		ref.seed([
			tag("font", {style:"font-size:18px"}, "<?= _("Edit ") ?>"), tag("a", {id:ref.id+".h1", href:"http://<?=engine_get('control.public')?>/<?=$letterloc?>&letterid=<?=$_set->vars->id?>", target:"_blank", style:"font-size:18px"}, "issue <?=$_set->vars->id?>"), " (view)", br, br,
			tag("input", {id:ref.id+".title"}), tag("div", {id:ref.id+".text"}),  br, tag("div", {id:ref.id+".objs"}),
			new Button({id:ref.id+".test", type:'letter', action:'button', descr:'test letter', letterid:<?=$_set->vars->id?>, tool:'text.letter', meta:{ value:1 }}),
			new Button({id:ref.id+".init", type:'letter', action:'init.batch', descr:'initiate send loop', letterid:<?=$_set->vars->id?>, tool:'text.letter', meta:{ value:1 }}),
			tag("br"),
			tag("font", {style:"font-size:11px"}, "Note: After initiating the send loop, do not close the browser until all newsletters have been sent. If the sending of newsletters is interrupted for any reason, clicking initiate send loop will resume the process from where it was stopped."),
			tag("div", {id:ref.id+".init.response"}, "idle"),
			tag("div", {id:ref.id+".comment", class:"comment"}),
			new Options({id:ref.id+".options", tool:'group.basic', descr:'Opties', floats: [
				new Shift({id:ref.id+".publish", type:'letter', action:'shift', descr:'is public', tool:'text.letter', meta:{ value:<?=($_letter['active']==1)?1:0;?>, options:[0,1], field:"active", objid:ref.vars.id}})
			], meta:{}})
		]);
		
		$(ref.id+".test").observe("focus", function(e) {
			this.vars.meta.lang = init.lang;
		});

		$(ref.id+".init").observe("focus", function(e) {
			this.vars.meta.lang = init.lang;
		});
		
		[	{id:ref.id+".title", descr:'title', direct:1, parenttype:"letter", parentid:<?=$_letter['ID']?>, traceback:<?= json_encode($_set->vars->traceback) ?>, textid:<?= $_letter['nameid'] ?>, values:<?=($title)?json_encode($title):"{}"?>},
			{id:ref.id+".text", rich:1, descr:'newsletter text', ref:'lettertext', parenttype:"letter", parentid:<?=$_letter['ID']?>, direct:1, textid:<?= $_letter['textid'] ?>, values:<?=($body)?json_encode($body):"{}"?>}
		].each(function(obj){ win.asset.txtfield.build(obj); });

	<? }



}
	
////////////////  NEWS ASSETS
if($_tool[1] == "news") {

////////////////// EDIT NEWSPOST
	
	if($_set->action == "edit" || $_set->action == "edit.new"){
	
		if($_set->action == "edit.new") {
			$DB->query("INSERT INTO mod_news (active, date, flog, creator) VALUES (0, NOW(), NOW(), ".$Engine->user('ID').")", 0 );
			$_set->vars->id = $DB->get_key( "news", "active=0 order by ID desc", "ID" );
			?>
			
			if(ref.vars.parent) {
				win.float.list["float_"+ref.vars.type+".<?=$_set->vars->id?>"] = obj = {id:<?=$_set->vars->id?>, type:ref.vars.type, tool:'text.news', name:"...", descr:"...", objtype:ref.vars.objtype, list:[{ref:'id'}, {ref:'descr'}, '<?=date("d.m y")?>'], meta:{} };
				//console.log( ref.vars.parent );
				//$(ref.vars.parent).vars.floatlist.push(<?=$_set->vars->id?>);
				//$(ref.vars.parent+".tbody").insert({top: new win.trfloat(obj)});
			}
			
			
			
			<? 
		}

		$_news		= $DB->get( "news", "ID=". $_set->vars->id, "*, YEAR(date) as year, MONTH(date) as month, DAY(date) as day, HOUR(date) as hour" );
		$title		= $Engine->text->filter( $_news['nameid'] );
		$body		= $Engine->text->filter( $_news['contid'], "long" );
		
		$_set->vars->traceback[] = $_set->trg.".h1";
	?>	

		ref.seed([
			tag("font", {style:"font-size:18px"}, "Edit "), tag("a", {id:ref.id+".h1", href:"http://<?=engine_get('control.public')?>/?page=news&publish=all", target:"_blank", style:"font-size:18px"}, "news post"), " (view)", br,
			tag("input", {id:ref.id+".ntle"}), tag("div", {id:ref.id+".text"}),
			tag("div", {id:ref.id+".comment", class:"comment"}),
			tag("div", {id:ref.id+".extra"})
		]);
		
		groups = { extra : [
			tag("div",{id:ref.id+".isactive"}),
			
	<?	if(engine_get('social.twitter.account')) {
			$tweetsoc = $DB->type("social.twitter");
				
			if( $social = $DB->query_direct( "select parentid from glue_social where objid = {$_set->vars->id} && parenttype = $tweetsoc" )) { 
				$tweetid = json_decode( $DB->query_direct("select meta from mod_social where ID = $social" ))->id;
				$twacc = json_decode( engine_get( 'social.twitter.account' )); 
	?>
			tag("font", {style:"font-size:12px"}, "Already tweeted: "), tag("a", {href:"http://twitter.com/<?= $twacc->username ?>/status/<?= $tweetid ?>"}, "here"),
	<?	} elseif( $DB->query_direct( "select ID from glue_social where objid = {$_set->vars->id} && parenttype = 23" )) {
	?>
			tag("font", {style:"font-size:12px"}, "Newspost has been marked for tweeting!"),
	<?	} else { ?>
			new Button({id:ref.id+'.tweet', type:'social', action:'tweet', descr:'post to twitter', tool:'social.interaction', meta:{objid:'<?=$_news['ID']?>'}}),
	<?	} } ?>
			tag("table",{cellpadding:"0", cellspacing:"0"},[
				tag("tr",0,[
					tag("td",0,[ tag("input",{id:ref.id+".publish.year", style:"width:124px;"}) ]),
					tag("td",0,[ tag("input",{id:ref.id+".publish.month", style:"width:62px;"}) ]),
					tag("td",0,[ tag("input",{id:ref.id+".publish.day", style:"width:62px;"}) ]),
					tag("td",0,[ tag("input",{id:ref.id+".publish.hour", style:"width:48px;"}) ])
				])
			])
		]};
		
		win.asset.group.build({id:ref.id+".extra", descr:'Specificaties', cont:groups.extra, open:1 });
		
		
		[	{id:ref.id+".ntle", descr:'title', direct:1, parenttype:"news", parentid:<?=$_news['ID']?>, textid:<?=$_news['nameid']?>, traceback:<?= json_encode($_set->vars->traceback) ?>,  values:<?=($title)?json_encode($title):"{}"?>},
			{id:ref.id+".text", rich:1, descr:'news text', ref:'newstxt', parenttype:"news", textid:<?=$_news['contid']?>, parentid:<?=$_news['ID']?>, direct:1, values:<?=($body)?json_encode($body):"{}"?>}
		].each(function(obj){ win.asset.txtfield.build(obj); });
	

		[	{id:ref.id+".isactive", type:'news', action:'shift', descr:'Published', tool:'text.news', meta:{ value:<?=$_news['active']?>, field:'active', objid:<?=$_news['ID']?> }}
		].each(function(obj){ win.asset.shift.build(obj); });

		[	{id:ref.id+".publish.year", descr:'Publish year', tool:"text.news.year", type:"news", meta: {value:<?=$_news['year']?>, objid:<?=$_news['ID']?>}},
			{id:ref.id+".publish.month", descr:'month', tool:"text.news.month", type:"news", meta: {value:<?=$_news['month']?>, objid:<?=$_news['ID']?>}},
			{id:ref.id+".publish.day", descr:'day', tool:"text.news.day", type:"news", meta: {value:<?=$_news['day']?>, objid:<?=$_news['ID']?>}},
			{id:ref.id+".publish.hour", descr:'hour', tool:"text.news.hour", type:"news", meta: {value:<?=$_news['hour']?>, objid:<?=$_news['ID']?>}}
		].each(function(obj){ win.asset.ajxfield.build(obj); });
		
	<? exit(); }

	
////////////////// NEWSLIST
	if($_set->action == "list"){ ?>
	
		ref.vars.parent = ref.id+'.dumplst';
		ref.seed([
			tag("font", {style:"font-size:18px"}, "<?= ucfirst($_set->vars->descr)?>"), br, br,
			new List({id:ref.id+".lst", tool:'text.news', descr:'Published news', new:'add <?=$DB->type_r( $_set->vars->objtype )?>', meta:ref.vars}),
			tag("div", {id:ref.id+".dump",style:"width:372px; margin-top:8px;"})
		]);
		
		$(ref.id+".lst").seed(<?= $_set->parse_list() ?>);
				
		win.asset.group.build(
			{id:ref.id+".dump", descr:'Unpublished / dumped', cont:[ new List({id:ref.id+".dumplst", tool:'text.news', descr:'', meta:Object.extend(ref.vars, {reqs:{active:0}} )}) ] }
		);


	<? }
}



///////////////// AJAX COMM //////////////////
} else if($_set->wtype == "push") {
//////////////////////////////////////////////

if($_set->action == "edit"){
	$key = ($_set->vars->rich)? "long":"short"; 
	$lang = ($_set->vars->lang)? get_object_vars($_set->vars->lang) : array();

	if(count($lang)) foreach($lang as $l) if($l) $update = true;
	if(!$update && $_set->vars->textid) { $comment = "dumped"; $DB->query("UPDATE `txtdump` SET active=0, llog=NOW() WHERE textid=".$_set->vars->textid); }

	if(!$_set->vars->textid || !$update) {
		$_set->vars->textid = ($update)? $Engine->text->maxid() +1 : 0;

		echo "win.asset.txtfield.list['".$_set->vars->id."'].textid = ".$_set->vars->textid.";\n";
		if($_set->vars->parentid) {

			if( $_set->vars->parenttype == "page" )
				$DB->query("UPDATE pages SET ".(($_set->vars->rich)?"textid":"nameid")."=".$_set->vars->textid." WHERE ID=".$_set->vars->parentid);
			
			else if( $_set->vars->parenttype == "mod" ) {
				$mod = $Modcon->request_json( $_set->vars->parentid );
				$mod->{ ($_set->vars->rich)?"textid":"nameid" } = (int) $_set->vars->textid;
				echo "UPDATE moddump SET json='". json_encode($mod) ."' WHERE ID=".$_set->vars->parentid;
				$DB->query("UPDATE moddump SET json='". json_encode($mod) ."' WHERE ID=".$_set->vars->parentid );
			
			} else  if( $_set->vars->parenttype=="news")
				$DB->query("UPDATE mod_".$_set->vars->parenttype." SET ".(($_set->vars->rich)?"contid":"nameid")."=".$_set->vars->textid." WHERE ID=".$_set->vars->parentid);
			
			else $DB->query("UPDATE mod_".$_set->vars->parenttype." SET ".(($_set->vars->rich)?"textid":"nameid")."=".$_set->vars->textid." WHERE ID=".$_set->vars->parentid);
				
		}
	}
	
	
	
	if( $update && $Engine->text->get( $_set->vars->textid, $key, $_set->vars->current, 1 )) { $comment = "updated";
		$DB->query("UPDATE txtdump SET `$key`=\"".str_replace(array("&lt;","&gt;",'"'),array("<",">","'"),$lang[$_set->vars->current])."\", llog=NOW() WHERE textid=".$_set->vars->textid." AND lang='".$_set->vars->current."'");
	} else if($update) { $comment = "created"; $DB->query("INSERT INTO `txtdump` (`textid`,`lang`,`$key`,`llog`,`author`) VALUES (".$_set->vars->textid.", '".$_set->vars->current."', ".$DB->smartq($lang[$_set->vars->current]).", NOW(), ".$_SESSION['uid'].")"); }
	?>
	xhttp.gfx("<?="$comment ".(($_set->vars->rich)?"text":$lang[$_set->vars->current]);?>", ref.id);
	

<? exit(); }



/////////// LIST CONTROL

if($_set->action == "list") { ?>

	$(ref.trg).seed(<?= $_set->parse_list() ?>);
	
<? exit(); }

if( strstr( $_set->action, "flow") ) { ?>
	
	$('control_list')._push(ref.trg, <?= $_set->flow() ?> );

<? exit(); }

	



/////////////////////////// ELEMENT ORDER / STATUS
////////////////// DUMP ELEMENT
if($_set->action == "kill") {
	// MOD
	if($_set->vars->type == "mod"){
		$_page = $DB->get( "page", "name='{$_set->vars->meta->page}'", "mods, ID");
		$_mods = json_decode( $_page['mods'] );
		unset($_mods->{$_set->vars->meta->column}->{$_set->vars->meta->mod});
		$DB->query("UPDATE `pages` SET mods='".json_encode($_mods)."', llog=NOW() WHERE `ID`=".$_page['ID']);
		
		foreach(array("nameid","textid","textid","nameid") as $id) if($val = $_set->vars->meta->modvars->{$id}) $textid[] = $val;
		$DB->query("UPDATE `txtdump` SET active=0, llog=NOW() WHERE textid IN(".implode(",",$textid).")");
		?>
		xhttp.gfx("<?=$_set->vars->name?> deleted", ref.id);

	<? }
	
	// NEWSPOST
	if($_set->vars->type == "text.news"){
		if($_set->vars->meta->active) {
			$DB->query("UPDATE mod_news SET active=0 WHERE ID=".$_set->vars->id);
			$comment = "node dumped";
		} else {
			$DB->query("UPDATE txtdump SET active=0 WHERE textid IN(SELECT n.nameid FROM mod_news as n WHERE n.ID=".$_set->vars->id.") OR textid IN(SELECT n.textid FROM mod_news as n WHERE n.ID=".$_set->vars->id.") and textid>0");
			$DB->query("DELETE FROM mod_news WHERE ID=".$_set->vars->id." LIMIT 1");
			$comment = "node removed!";
		}
		?>
			xhttp.gfx("<?=$comment?>", ref.id);
	<? }
	
exit(); }

////////////////// SHIFT FUNCTIONALITIES
if($_set->action == "shift") {

	$comment = ( $_set->shift() )? "option modified":"warning: failed";

	?>
	xhttp.gfx("<?=$comment?>", ref.id);
	<?
	
exit(); }


////////////////// LETTER FUNCTIONALITIES
if($_set->action == "button" && $_set->type=="letter") {

	include_once "engine/www/class/MAILER.php";

	$LETTER = new MAILER("html");

	if ($_set->vars->letterid) {

		$LETTER->_generate_newsletter($_set->vars->letterid, $_set->vars->meta->lang, $Engine->user('ID'));
		$LETTER->_send();

		$comment = "Sent a sample newsletter.";
	}

	?>
	xhttp.gfx("<?=$comment?>", $(ref.trg).ancestors()[1].id+".init.response");
	<?
exit(); }

////////////////// LETTER LOOP INIT
if($_set->action == "init.batch" && $_set->type=="letter") {

	?>
	letter_amount = <?= $DB->query_direct( "select count(*) from mod_user where lletter < {$_set->vars->letterid} && lang = '{$_set->vars->meta->lang}'" ) ?>;
	xhttp.gfx("initiated, for "+ letter_amount +" users", ref.trg+".response");
	xhttp.send('control.call.php', {trg:ref.trg, wtype:'push', type:"letter", tool:"text.letter", action:"batch.loop", vars:{letterid:<?=$_set->vars->letterid?>, meta:{lang:'<?=$_set->vars->meta->lang?>'}} });
	$(ref.trg).value = "stop sending";
	$(ref.trg).vars.action = "batch.cancel";
	<?
exit(); }

////////////////// LETTER LOOP LOOP
if($_set->action == "batch.loop" && $_set->type=="letter") {

	?>
	$(ref.trg).tm = setTimeout(function() {
		<?
		include_once "engine/www/class/MAILER.php";
		$LETTER = new MAILER("html");
		if ($_set->vars->letterid) {
		#	$LETTER->_generate_newsletter($_set->vars->letter, $_set->vars->language, $Engine->user('ID'));
			$LETTER->_generate_newsletter($_set->vars->letterid, $_set->vars->meta->lang, "lletter < ". $_set->vars->letterid . " AND lang = \"". $_set->vars->meta->lang . "\" LIMIT 98");
	 		
	 		if( $success = $LETTER->_send() )
				$DB->query("UPDATE mod_user set lletter = " . $_set->vars->letterid . " WHERE ID in(" . implode(", ", $success) . ")");
		}
		?>
		letter_amount -= 98
		xhttp.gfx("remaining: "+ ((letter_amount > 0)? letter_amount: 0), ref.trg+".response"); 
		if( letter_amount < 1)
				xhttp.send('control.call.php', {trg:ref.trg, wtype:'push', type:"letter", tool:"text.letter", action:"loop.end", vars:{letterid:<?=$_set->vars->letterid?>, meta:{lang:'<?=$_set->vars->meta->lang?>'}} });
		else 	xhttp.send('control.call.php', {trg:ref.trg, wtype:'push', type:"letter", tool:"text.letter", action:"batch.loop", vars:{letterid:<?=$_set->vars->letterid?>, meta:{lang:'<?=$_set->vars->meta->lang?>'}} });
	
	
	}, 1000);
	
	<?
exit(); }

////////////////// LETTER LOOP LOOP
if($_set->action == "batch.cancel" && $_set->type=="letter") {
	?>
	
	letter_amount = 0;
	xhttp.gfx("cancelled!", ref.trg+".response");
	$(ref.trg).value = "continue send loop";
	$(ref.trg).vars.action = "batch.loop";
	clearTimeout( $(ref.trg).tm );
		
	<?
exit(); }

////////////////// LETTER LOOP END
if($_set->action == "loop.end" && $_set->type=="letter") {

	?>
	xhttp.gfx("all done, go home.", ref.trg+".response");
	$(ref.trg).value = "send loop again";
	$(ref.trg).disabled = true;
	<?
exit(); }



////////////////// AJAX (direct) UPDATE FUNCTIONALITIES
if($_set->action == "ajax") {
	
	if(!$_set->vars->meta->field) {
		if($_tool[1]=="news") {
			$ref = $DB->get( "news", "ID=". $_set->vars->meta->objid, "pdate, ". $_tool[2] ."(pdate) as itv" );
			$date = date_create($ref['pdate']);
			$date->modify( ($_set->vars->meta->value - $ref['itv'])." ".$_tool[2]);
			
			$_set->vars->meta->value = $date->format("Y-m-d H:00:00");
			$_set->vars->meta->field = "pdate";
		}
	}
	
	$comment = ( $_set->ajax() )? "updated option":"warning: failed";
	
	?>
	xhttp.gfx("<?=$comment?>", ref.id);
	<?
	
exit(); }


}